package com.whfp.coky.other

import android.content.Context
import com.whfp.coky.R
import com.whfp.coky.ui.base.BaseDialog
import com.whfp.coky.ui.dialog.InputPwdDialog
import com.whfp.coky.ui.dialog.MessageDialog
import com.whfp.coky.ui.dialog.SelectDialog
import com.whfp.coky.utils.ToastUtil

/**
 *
 *
 * created by coky on 2022/3/19
 */
class DialogBuilder {
    companion object{
        /**
         * 单选弹窗
         */
        fun selectSingle(context: Context, currSelectSingle:Int = 0,title:String, listData:MutableList<Any>, doConfirm: (data: HashMap<Int, String>)->Unit){
            // 单选对话框
            SelectDialog.Builder(context)
                .setTitle(title)
                .setList(listData)
                // 设置单选模式
                .setSingleSelect()
                // 设置默认选中
                .setSelect(currSelectSingle)
                .setListener(object : SelectDialog.OnListener<String> {
                    override fun onSelected(dialog: BaseDialog?, data: HashMap<Int, String>) {
                        doConfirm(data)
                    }
                    override fun onCancel(dialog: BaseDialog?) {
                        dialog?.dismiss()
                    }
                })
                .show()
        }

        /**
         * 输入密码弹窗
         */
        fun inputPwdDialog(context: Context, title:String, content:String, doConfirm: (str:String?)->Unit) {
            // 消息对话框
            InputPwdDialog.Builder(context)
                // 内容必须要填写
                .setContent(content)
                // 设置点击按钮后不关闭对话框
                //.setAutoDismiss(false)
                .setListener(object : InputPwdDialog.OnListener {
                    override fun onConfirm(dialog: BaseDialog?, content: String) {
                        if (content.isNullOrEmpty()){
                            ToastUtil.showToast(context,"管理员密码不可为空！")
                        }else{
                            doConfirm(content)
                        }
                    }

                    override fun onCancel(dialog: BaseDialog?) {
                       dialog?.cancel()
                    }
                })
                .show()
        }
        @JvmStatic
        fun DialogMsg(
            context: Context,
            title: String?,
            content: String?,
            comfirm: Int,
            listener: MessageDialog.OnListener?
        ): MessageDialog.Builder? {
            return MessageDialog.Builder(context) // 标题可以不用填写
                .setTitle(title) // 内容必须要填写
                .setMessage(content) // 确定按钮文本
                .setConfirm(comfirm) // 设置 null 表示不显示取消按钮
                .setCancel(R.string.common_cancel) // 设置点击按钮后不关闭对话框
                //.setAutoDismiss(false)
                .setListener(listener)
        }


    }
}